%{?!tool_name: %global tool_name hosttools}
%global tool_prefix /opt/%{tool_name}

Summary: A GNU collection of binary utilities
Name: %{tool_name}-binutils
Version: 2.38
Release: 1
License: GPLv3+
URL: https://sourceware.org/binutils

# Perl, sed and touch are all used in the %%prep section of this spec file.
BuildRequires: gcc, make, perl, sed, coreutils, lzip, texinfo

Source: https://ftp.gnu.org/gnu/binutils/binutils-%{version}.tar.lz

%description
Binutils is a collection of binary utilities, including ar (for
creating, modifying and extracting from archives), as (a family of GNU
assemblers), gprof (for displaying call graph profile data), ld (the
GNU linker), nm (for listing symbols from object files), objcopy (for
copying and translating object files), objdump (for displaying
information from object files), ranlib (for generating an index for
the contents of an archive), readelf (for displaying detailed
information about binary files), size (for listing the section sizes
of an object or archive file), strings (for listing printable strings
from files), strip (for discarding symbols), and addr2line (for
converting addresses to file and line).

%prep
%setup -q -n binutils-%{version}

%build
mkdir build-binutils
cd build-binutils
../configure --prefix=%{tool_prefix} \
  --disable-multilib \
  --enable-lto \
  --disable-gold \
  --disable-nls
make %{?_smp_mflags}

%install
cd build-binutils
make DESTDIR=%{buildroot} install
rm -f %{buildroot}%{tool_prefix}/share/info/dir
rm -rf %{buildroot}%{tool_prefix}/share/man/man7
find %{buildroot} -name '*.la' -delete

%files
%{tool_prefix}/bin/*
%{tool_prefix}/lib/*
%{tool_prefix}/include/*
%{tool_prefix}/x86_64-pc-linux-gnu/bin/*
%{tool_prefix}/x86_64-pc-linux-gnu/lib/ldscripts
%{tool_prefix}/share/info/*
%{tool_prefix}/share/man/man1/*
